package ilearn.job.disserver.acconut.controller;

import com.fasterxml.jackson.core.JacksonException;
import ilearn.job.disserver.acconut.entity.Account;
import ilearn.job.disserver.acconut.service.AccountService;
import ilearn.job.disserver.sdk.account.RabbitMQSender;
import ilearn.job.disserver.sdk.account.dto.AccountDTO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Log4j2
public class AccountController {

    @Resource
    private AccountService accountService;
    @Autowired
    private RabbitMQSender rabbitMQSender;

    @GetMapping("/getUser")
    public Account getUser(Long id){
        return accountService.getAccountById(id);
    }

    @PutMapping("/updateUser")
    public Account putAccount(@RequestBody AccountDTO accountDTO) throws JacksonException {
        log.info("开始用户注册/更新：{}",accountDTO);
        Account account = accountService.putAccount(accountDTO);
        rabbitMQSender.send(accountDTO);
        return account;
    }
}
